package com.huang.lesson05;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;

public class UdpSend {
    public static void main(String[] args) throws Exception {
        DatagramSocket socket = new DatagramSocket();

        //从控制台输入 传输的数据
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        while (true){
            String line = reader.readLine();
            byte[] msg = line.getBytes();
            DatagramPacket packet = new DatagramPacket(msg,0,msg.length,InetAddress.getByName("localhost"),8081);

            socket.send(packet);
            if(line.equals("bye")){
                break;
            }
        }


        socket.close();
    }
}
